#include<bits/stdc++.h>
using namespace std;
#define int long long
int read(){
    int n=0,f=1;
    char ch=getchar();
    while(!isdigit(ch)){
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(isdigit(ch)){
        n=n*10+ch-'0';
        ch=getchar();
    }
    return n*f;
}
int n,m,L,v;
int d[100005],a[100005],p[100005];
int pos[100005];
int l[100005],r[100005];
void work(){//Solve the first one.
    int res=0;
    for(int i=1;i<=n;i++){
        l[i]=r[i]=-1;
        if(a[i]==0){
            //Non changing speed p[i].
            if(p[i]>v){
                //>=d[i]
                if(pos[m]>=d[i]){
                    res++;
                    l[i]=lower_bound(pos+1,pos+m+1,d[i])-pos;
                    r[i]=m;
                }
            }
        }
        else if(a[i]>0){
            if(p[i]>v){
                if(pos[m]>=d[i]){
                    res++;
                    l[i]=lower_bound(pos+1,pos+m+1,d[i])-pos;
                    r[i]=m;
                }
            }
            else{
                //Only when 2a[i]s>v^2-p[i]^2, exceeds
                int lb=v*v-p[i]*p[i];
                if(lb%(2*a[i])==0)lb=lb/(2*a[i]),lb++;
                else lb=(lb+2*a[i]-1)/(2*a[i]);
                //go lb at least.
                int cur=d[i]+lb;
                if(pos[m]>=cur){
                    res++;
                    l[i]=lower_bound(pos+1,pos+m+1,cur)-pos;
                    r[i]=m;
                }
            }
        }
        else{
            if(p[i]>v){
                int lb=v*v-p[i]*p[i];
                lb=-lb;
                if(lb%((2*(-a[i])))==0)lb/=(2*(-a[i])),lb--;
                else lb/=(2*(-a[i]));
                lb+=d[i];
                //<d[i]+
                int tmp=p[i]*p[i]/(2*(-a[i]));
                lb=min(lb,d[i]+tmp);
                //cout<<"qwerty"<<d[i]<<" "<<lb<<"\n";
                //in [d[i],lb]
                if(d[i]<=lb&&pos[m]>=d[i]&&pos[1]<lb){
                    int ql=lower_bound(pos+1,pos+m+1,d[i])-pos;
                    int qr=upper_bound(pos+1,pos+m+1,lb)-pos-1;
                    //cout<<"uiop"<<ql<<" "<<qr<<"\n";
                    if(ql<=qr){
                        res++;
                        l[i]=ql,r[i]=qr;
                    }
                }
            }
        }
    }
    cout<<res<<" ";
    //for(int i=1;i<=n;i++){
    //    cout<<l[i]<<" "<<r[i]<<"\n";
    //}
}
int dir[100005];
void solve(){
    n=read(),m=read(),L=read(),v=read();
    for(int i=1;i<=n;i++){
        d[i]=read(),p[i]=read(),a[i]=read();
    }
    for(int i=1;i<=m;i++)pos[i]=read();
    work();
    //[l,r] speed test.
    for(int i=1;i<=m;i++)dir[i]=(1ll<<60);
    for(int i=1;i<=n;i++){
        if(l[i]==-1)continue;
        dir[l[i]]=min(dir[l[i]],r[i]);
        //l[i] to r[i].
    }
    int ql=0,qr=(1ll<<60);
    int cnt=0;
    for(int i=1;i<=m;i++){
        if(dir[i]<=m){
            int tl=i,tr=dir[i];
            if(ql>tl)swap(ql,tl),swap(qr,tr);
            ql=tl,qr=min(qr,tr);
            if(ql>qr){
                ++cnt;
                ql=i,qr=dir[i];
            }
            //[ql,qr]
            //[tl,tr]
        }
    }
    if(qr!=(1ll<<60))++cnt;
    cout<<m-cnt<<"\n";
}
signed main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t=read();
    while(t--)solve();
    return 0;
}
//Why does a Java programmer have eyesight problems?
//Because he can't C#.
